// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class StartDatafeedRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>
/// Start datafeeds.
/// </para>
/// <para>
/// A datafeed must be started in order to retrieve data from Elasticsearch. A datafeed can be started and stopped
/// multiple times throughout its lifecycle.
/// </para>
/// <para>
/// Before you can start a datafeed, the anomaly detection job must be open. Otherwise, an error occurs.
/// </para>
/// <para>
/// If you restart a stopped datafeed, it continues processing input data from the next millisecond after it was stopped.
/// If new data was indexed for that exact millisecond between stopping and starting, it will be ignored.
/// </para>
/// <para>
/// When Elasticsearch security features are enabled, your datafeed remembers which roles the last user to create or
/// update it had at the time of creation or update and runs the query using those same roles. If you provided secondary
/// authorization headers when you created or updated the datafeed, those credentials are used instead.
/// </para>
/// </summary>
public sealed partial class StartDatafeedRequest : PlainRequest<StartDatafeedRequestParameters>
{
	public StartDatafeedRequest(Elastic.Clients.Elasticsearch.Id datafeedId) : base(r => r.Required("datafeed_id", datafeedId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningStartDatafeed;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.start_datafeed";

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("end")]
	public DateTimeOffset? End { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("start")]
	public DateTimeOffset? Start { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>timeout</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("timeout")]
	public Elastic.Clients.Elasticsearch.Duration? Timeout { get; set; }
}

/// <summary>
/// <para>
/// Start datafeeds.
/// </para>
/// <para>
/// A datafeed must be started in order to retrieve data from Elasticsearch. A datafeed can be started and stopped
/// multiple times throughout its lifecycle.
/// </para>
/// <para>
/// Before you can start a datafeed, the anomaly detection job must be open. Otherwise, an error occurs.
/// </para>
/// <para>
/// If you restart a stopped datafeed, it continues processing input data from the next millisecond after it was stopped.
/// If new data was indexed for that exact millisecond between stopping and starting, it will be ignored.
/// </para>
/// <para>
/// When Elasticsearch security features are enabled, your datafeed remembers which roles the last user to create or
/// update it had at the time of creation or update and runs the query using those same roles. If you provided secondary
/// authorization headers when you created or updated the datafeed, those credentials are used instead.
/// </para>
/// </summary>
public sealed partial class StartDatafeedRequestDescriptor : RequestDescriptor<StartDatafeedRequestDescriptor, StartDatafeedRequestParameters>
{
	internal StartDatafeedRequestDescriptor(Action<StartDatafeedRequestDescriptor> configure) => configure.Invoke(this);

	public StartDatafeedRequestDescriptor(Elastic.Clients.Elasticsearch.Id datafeedId) : base(r => r.Required("datafeed_id", datafeedId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningStartDatafeed;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.start_datafeed";

	public StartDatafeedRequestDescriptor DatafeedId(Elastic.Clients.Elasticsearch.Id datafeedId)
	{
		RouteValues.Required("datafeed_id", datafeedId);
		return Self;
	}

	private DateTimeOffset? EndValue { get; set; }
	private DateTimeOffset? StartValue { get; set; }
	private Elastic.Clients.Elasticsearch.Duration? TimeoutValue { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	public StartDatafeedRequestDescriptor End(DateTimeOffset? end)
	{
		EndValue = end;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	public StartDatafeedRequestDescriptor Start(DateTimeOffset? start)
	{
		StartValue = start;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>timeout</c> query parameter.
	/// </para>
	/// </summary>
	public StartDatafeedRequestDescriptor Timeout(Elastic.Clients.Elasticsearch.Duration? timeout)
	{
		TimeoutValue = timeout;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (EndValue is not null)
		{
			writer.WritePropertyName("end");
			JsonSerializer.Serialize(writer, EndValue, options);
		}

		if (StartValue is not null)
		{
			writer.WritePropertyName("start");
			JsonSerializer.Serialize(writer, StartValue, options);
		}

		if (TimeoutValue is not null)
		{
			writer.WritePropertyName("timeout");
			JsonSerializer.Serialize(writer, TimeoutValue, options);
		}

		writer.WriteEndObject();
	}
}